﻿using System.Linq;
using FacialClub.Models.Entities;
using FacialClub.Models.Interfaces;
namespace FacialClub.Models.Repositories
{
    /// <summary>
    /// Lead Type Repository
    /// </summary>
    public class LeadTypeRepository : ILeadTypeRepository
    {
        readonly FacialClubEntities _db = new FacialClubEntities();

        /// <summary>
        /// Get Lead Type Details by Title
        /// </summary>
        /// <param name="strQuery"></param>
        /// <returns></returns>
        public IQueryable<LeadType> FindLeadTypeByName(string strQuery)
        {
            return _db.LeadTypes.Where(d => d.LeadTypeName.Contains(strQuery));
        }

        /// <summary>
        /// Get All Lead Type
        /// </summary>
        /// <returns></returns>
        public IQueryable<LeadType> FindAllLeadType()
        {
            return _db.LeadTypes;
        }

        /// <summary>
        /// Get Lead Type by Id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public LeadType GetLeadTypeById(int id)
        {
            return _db.LeadTypes.SingleOrDefault(d => d.LeadTypeId == id);
        }

        /// <summary>
        /// Add Lead Type in the Database
        /// </summary>
        /// <param name="leadType"></param>
        public void Add(LeadType leadType)
        {
            _db.LeadTypes.AddObject(leadType);
        }

        /// <summary>
        /// Delete Lead Type from Database
        /// </summary>
        /// <param name="leadType"></param>
        public void Delete(LeadType leadType)
        {
            _db.LeadTypes.DeleteObject(leadType);
        }

        /// <summary>
        /// Save Lead Type in the database
        /// </summary>
        public void Save()
        {
            _db.SaveChanges();
        }
    }
}